package com.tang.campus_market.dao;

import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.tang.campus_market.entity.Goods;
import org.apache.ibatis.annotations.*;

import java.util.Date;
import java.util.List;

@Mapper
public interface GoodsDao extends BaseMapper<Goods> {
    @Select("SELECT * FROM market_goods")
    List<Goods> findAll();

    @Update("update market_comment set state=0 where goods_id = #{id}")
    void updateCommentStateById(Integer id);

    @Update("update market_order set status=0 where good_id = #{id}")
    void updateOrderStateById(Integer id);

    @Update("update market_goods set state=0 where id = #{id}")
    void updateGoodById(Integer id);

    @Update("update market_goods set state=1 where id = #{id}")
    void updateGoodOnById(Integer id);

    @Update("update market_order set status=0 where good_id = #{id}")
    void updateOrderById(Integer id);

    @Select("SELECT * FROM market_goods " )
    List<Goods> queryAll();
    //    根据名字查询
    @Select("SELECT * FROM market_goods where title = #{goodsName}" )
    List<Goods> queryByName(String goodsName);
    //    添加数据
    @Insert("insert into market_goods(user_id,title,introduction,price,first_class,second_class,picture,create_date,modify_date) values(#{userId},#{goodsName},#{describe},#{price},#{first_class},#{second_class},#{image},#{create_date},#{modify_date})")
    void CraeteGoods(String userId, String goodsName, String describe, Integer price, String first_class, String second_class, String image,Date create_date, Date modify_date);
    //    删除商品
    @Delete("delete from market_goods where id = #{id}")
    void DeleteGood(Integer id);
    //    修改商品
    @Update("update market_goods set title=#{goodsName},introduction=#{describe},price=#{price},first_class=#{first_class},second_class=second_class,picture=#{image} where id = #{id}")
    void UpdateGood(Integer id,String goodsName,String describe,Integer price,String first_class,String second_class,String image);
    //    修改商品状态
    @Update("update market_goods set state=#{goodsState} where id = #{id}")
    void updateGoodState(String goodsState,Integer id);

    @Update("update market_goods set sale_state=#{saleState} where id = #{id}")
    void updateGoodSaleState(String saleState,Integer id);
}
